<template>
	<view>
		<view class="mui-content" id="recharge-view" style="padding-left:20px;margin-right: 20px;">
			<view class='reminder'>1元购买1积分</view>
			<view class="box-a">
				<view style="float: left;padding: 20rpx 0 20rpx 0;color: #baafaf;">积分购买</view>
				<view id="records" @click="records()" style="text-align:right;color: #FF6600;padding: 20rpx 0 20rpx 0;">我的充值记录</view>
				<input :class="chongzhiMoney==100?'active':'noactive'" @click="jine(100)" type="button" disabled class="box-a-1" style="border: 1px solid #FF6700;border-radius: 6px;" value="100积分" />
				<input :class="chongzhiMoney==200?'active':'noactive'" @click="jine(200)" type="button" disabled class="box-a-1" style="border: 1px solid #FF6700;border-radius: 6px;" value="200积分" />
				<input :class="chongzhiMoney==500?'active':'noactive'" @click="jine(500)" type="button" disabled class="box-a-1" style="border: 1px solid #FF6700;border-radius: 6px;" value="500积分" />
				<input :class="chongzhiMoney==0?'active':'noactive'" @click="jine(0)" type="button" disabled class="box-a-2" style="border: 1px solid #FF6700;border-radius: 6px;" id="other" value="其他">
			</view>
			<view class='present'>充值赠送10%积分，如充值100到账110积分</view>
			<view class='present'>此积分只能用于消费无法退还，请勿多充</view>
			<view :class="isZidingyi?'input-number1':'input-number'"><input type="digit" @input="onInput" pattern="\d*" v-model="mobile" id="import" placeholder="请输入需要充值的数量" value=""></view>
			<view id="caution">请输入10的倍数</view>
			<view class="price">支付金额：<span id="price">{{chongzhiMoney}}</span>元</view>
			<view class="pay" @click="pay()">支付</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				chongzhiMoney: 100,//充值金额
				isZidingyi:false,  //是否自定义充值金额
				mobile: '',		   //文本框的值
			}
		},
		methods: {
			jine(e){
				this.chongzhiMoney=e;
				if(e==0){
					this.isZidingyi=true;
				}else{
					this.isZidingyi=false;
				}
			},
			onInput(e){
				this.chongzhiMoney=e.target.value;
				if(this.chongzhiMoney==100 || this.chongzhiMoney==200 || this.chongzhiMoney==500){
					this.mobile='';
					this.isZidingyi=false;
				}
			},
			pay(){
				if(this.chongzhiMoney < 0){
					this.$u.toast("充值金额不能为负数");
					return;
				}
				if(this.chongzhiMoney < 1){
					this.$u.toast("充值金额需大于等于一元");
					return;
				}
				// if(!(/(^[1-9]\d*$)/.test(this.chongzhiMoney))){
				// 	this.$u.toast("充值金额只能为正整数");
				// 	return;
				// }
				uni.navigateTo({
					url:'rechargeOrder?money='+this.chongzhiMoney
				})
			},
			records(){
				uni.navigateTo({
					url:'rechargeRecord'
				})
			}
		}
	}
</script>

<style>
	.active{
		color: #FFFFFF;
		background-color: #FF6700;
	}
	.noactive{
		background-color: #efeff4;
	}
	#import{
		padding: 15rpx 0 15rpx 0;
		margin:30rpx 0 30rpx 0;
	}
	.nav-header {
		background-color: #000000;
		color: white;
	}
	.nav-header h1 {
		text-align: left;
	}
	.nav-header a {
		color: white;
	}
	.reminder {
		text-align: center;
		line-height: 40px;
		color: #baafaf;
		border-bottom: 1px solid #dfd0d0;
	}
	.box-a-1 {
		width: 24%;
		height: 30px;
		float: left;
		margin-right: 2%;
		border-radius: 6px;
		text-align: center;
		line-height: 30px;
		font-size: 14px;
	}
	#other {
		width: 17%;
		border: 1px solid #FF6700;
		height: 30px;
		float: left;
		margin-right: 2%;
		border-radius: 6px;
		text-align: center;
		line-height: 30px;
		font-size: 14px;
	}
	.present {
		text-align: center;
		line-height: 40px;
		font-size: 12px;
		color: #baafaf;
	}
	.input-number {
		display: none;
	}
	.input-number1{
		display: block;
	}
	#caution {
		line-height: 5px;
		color: #FF6700;
		display: none;
	}
	#import {
		text-align: center;
		background-color: #efeff4;
	}
	.price {
		text-align: center;
		line-height: 10px;
		font-size: 14px;
		color: #baafaf;
	}
	.pay {
		height: 40px;
		background: #FF6700;
		border-radius: 6px;
		text-align: center;
		line-height: 40px;
		margin-top: 20px;
		color: #FFFFFF;
	}
</style>
